<?php

namespace App\Transformers;

use App\Models\Category;
use League\Fractal\TransformerAbstract;

class CategoryTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['companies'];
    public function transform(Category $category)
    {
        return [
            'id' => $category->id,
            'name' => $category->name,
            'ordernum' => $category->ordernum,
            'description' => $category->description,
        ];
    }

    public function includeCompanies(Category $category)
    {
        $companies = $category->companies;

        return $this->collection($companies, new CompanyTransformer());
    }

}